package cn.song.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class WechatMpConfig {

    @Autowired
    private WecharAcountConfig wecharAcountConfig;

    @Bean
    public WxMpService getWxMpService(){
        WxMpServiceImpl mpService = new WxMpServiceImpl();
        mpService.setWxMpConfigStorage(getWxMpConfigStorage());
        return  mpService;
    }

    @Bean
    public WxMpConfigStorage getWxMpConfigStorage(){
        WxMpInMemoryConfigStorage storage = new WxMpInMemoryConfigStorage();
        storage.setAppId(wecharAcountConfig.getMpAppId());
        storage.setSecret(wecharAcountConfig.getMpAppSecret());
        return  storage;
    }
}

